package xyz.weizhi.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import xyz.weizhi.tanhua.dubbo.mapper.UserMapper;
import xyz.weizhi.tanhua.model.domain.User;

/**
 * @Author million
 * @Date 2021/10/21 0021 20:15
 */
@DubboService
public class UserApiImpl implements UserApi{
    @Autowired
    private UserMapper userMapper;
    @Override
    public User findUserByPhone(String phone) {
        QueryWrapper<User> qw = new QueryWrapper<>();
        qw.eq("mobile", phone);
        return userMapper.selectOne(qw);
    }
    @Override
    public Long save(User user) {
        userMapper.insert(user);
        return user.getId();
    }

    @Override
    public void updatePhone(Long userId,String newPhone) {
        UpdateWrapper<User> uw = new UpdateWrapper<>();
        uw.eq("id", userId);
        uw.set("mobile", newPhone);
        userMapper.update(null,uw);
    }
}
